const http    = require('https'),
	  fs      = require('fs'),
      cheerio = require('cheerio'),
      log     = console.log,
      print   = require('util').debuglog('dev'),
      addr    = 'https://maoyan.com/films?showType=3';
	  
//const app = http.createServer();//(创建服务器)
//var server  = http.createServer();
var list = [];
//var ans =
http.get(addr, (res) => {
  let result = '';

  res.on('data', (data) => {
    result += data.toString('utf8');   
  });
  //console.log(result);
  //console.log('上边没东西输出');
  res.on('end', () => {
    //console.log(result);

    let $ = cheerio.load(result);
	console.log($('body').find('dd').length);
    $('body').find('dd').each(function(index){
      let movieName = $(this).find('dd>.movie-item-title>a').text();
	  let movieId = $(this).find('dd>.movie-item-title>a').attr('href');
	  //log(movieName);
	  movieId = movieId.split('/');
	  //log(movieId[2]);
	  let movieRange = $(this).find('dd>.channel-detail-orange>.integer').text();
	  if(movieRange === '')
		movieRange = $(this).find('dd>.channel-detail-orange').text();
	  else 
		movieRange += $(this).find('dd>.channel-detail-orange>.fraction').text();
	  //log(movieRange);
	  //log();
	  var obj = new Object();
	  obj.movieId = movieId[2];
	  obj.movieName = movieName;
	  obj.movieRange = movieRange;
	  //log(obj);
	  //log('shangbainshi obj');
	  list[index] = obj;

    });
	console.log(list);
	//console.log(list.json());
    //export {list};
  });
});